package hc;

import com.hazelcast.config.Config;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.topic.ITopic;
import test.PerformanceAnalyze;

public class TopicTest01 {

    test.PerformanceAnalyze analyze = new PerformanceAnalyze();


    void start() {
        Config config = new Config();
        config.getNetworkConfig().setPublicAddress("127.0.0.1");
        HazelcastInstance hzInstance = Hazelcast.newHazelcastInstance(config);

        for (int i = 0; i < 100000; i++) {
            ITopic<Long> topic = hzInstance.getTopic("topic"+i);
            topic.addMessageListener(message -> {
                analyze.delay(System.currentTimeMillis() - message.getMessageObject());
                analyze.meter();
            });
        }
    }

    public static void main(String[] args) {

        new TopicTest01().start();
    }
}
